﻿
Imports System.Threading
Imports std
Imports storoomc

Namespace counterUploader
    Public Module counterUploader
        Private Class _counterUploader
            Inherits uploader(Of pair(Of String, Int64))

            Protected Overrides Sub addWriteEventHandler()
                AddHandler counter.writeCounter, AddressOf writeCounterHandler
            End Sub

            Private Sub writeCounterHandler(ByVal name As String, ByVal count As Int64)
                push_queue(make_pair(name, count))
            End Sub

            Protected Overrides Sub removeWriteEventHandler()
                RemoveHandler counter.writeCounter, AddressOf writeCounterHandler
            End Sub

            Protected Overrides Function upload(ByVal v As pair(Of String, Int64)) As Boolean
                Return tablestore.write(applicationSign(), v.first, Convert.ToString(v.second), talk)
            End Function
        End Class

        Private _uploader As _counterUploader = Nothing

        Sub New()
            _uploader = New _counterUploader()
        End Sub

        Public Function initial(ByVal storoom As pair(Of String, Int32)) As Boolean
            Return _uploader.initial(storoom)
        End Function

        Public Function initial() As Boolean
            Return _uploader.initial()
        End Function
    End Module
End Namespace
